package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.BusinessParam;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import com.tarena.lbs.business.pojo.vo.BusinessStoreVO;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import com.tarena.lbs.business.servcie.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理和商家相关的接口功能
 */
@Slf4j
@RestController
@Api(tags = "商家相关功能接口")
public class BusinessController {

    private BusinessService businessService;

    @Autowired
    public void setBusinessService(BusinessService businessService) {
        this.businessService = businessService;
    }

    //商家的分页列表查询
    //读数据入参 单个属性 id name 对象数据 query结尾
    @ApiOperation(value = "查询商家列表")
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery query) {
        PageResult<BusinessVO> pageResult = businessService.pageList(query);
        return new Result<>(pageResult);
    }
    //表单填写完毕 新增提交商家数据保存
    //form请求表单格式参数 key=value&key=value
    //请求体携带json {"key","value"}
    //lbs智慧营销项目中 写操作 如果多个属性 命名类型Param后缀
    @ApiOperation(value = "新增商家")
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> save(@RequestBody BusinessParam param) {
        businessService.save(param);
        return Result.success();
    }
    //商家的业务中 活动查询商家 和旗下店铺列表封装
    @ApiOperation(value = "商家详情")
    @GetMapping("/admin/basic/business/info/detail/{id}")
    public Result<BusinessStoreVO> businessStoreDetail(@PathVariable("id") Integer businessId) {
        BusinessStoreVO businessStoreVO = businessService.businessStoreDetail(businessId);
        return new Result<>(businessStoreVO);
    }
}




















